package MainPack;

/*--------------------------------------------------
 * Class ImageCanvas
 *
 * Draw mutable image
 *-------------------------------------------------*/

import MaterialPack.Animation;
import MaterialPack.Button;
import javax.microedition.midlet.*;
import java.util.*;
import javax.microedition.lcdui.*;
import javax.xml.parsers.FactoryConfigurationError;
class ImageCanvas extends Canvas implements CommandListener {
	private Command cmExit; // Exit midlet

	private MainMIDlet midlet;

        
	private Image background = null;
        private Button button = null;

	private String message = "developerWorks";
        
        // animation
        private Animation animation = null;
        private Timer timer ;
        private Sticker sticker ;
        class Sticker extends TimerTask
        {
            public void run()
            {
                animation.next();
                repaint();
                
            }
        }


	public ImageCanvas(MainMIDlet _midlet)
        {
            midlet = _midlet;
            
            cmExit = new Command("Exit", Command.EXIT, 1);
            addCommand(cmExit);
            setCommandListener(this);
            
            button = new Button("Res/MenuIcon05.png", "Res/MenuIcon06.png", "Res/MenuIcon06.png", "abc", 100, 150, 40, 20);
            try
            {
                animation = new Animation(100,100,"Res/Attack.png");
                
                timer = new Timer();
                sticker = new Sticker();
                
                timer.schedule(sticker, 100,100);
                
                background  = Image.createImage(this.getWidth(),this.getHeight());

                Graphics graphic = background.getGraphics();
                graphic.setColor(128, 128, 128);
                graphic.fillRoundRect(0, 0, background.getWidth(), background.getHeight(), background.getWidth()/2, background.getHeight()/2);

                Font font = Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN   ,Font.SIZE_LARGE);
                graphic.setColor(255);
                graphic.drawString("I am Van",20,this.getHeight() - 10, Graphics.BOTTOM | Graphics.LEFT);
            }
            catch (Exception e)
            {
                e.printStackTrace();;
            }
        }
        public void paint(Graphics g)
        {
           if(background != null)
           {
                g.drawImage(background,0 , 0 , Graphics.TOP |Graphics.LEFT);
           }
           
           animation.paint(g);
           button.paint(g);
        }
        
	public void commandAction(Command c, Displayable d) {
		if (c == cmExit)
                {
                    timer .cancel();			
                    midlet.exitMIDlet();
                }
	}
        
        
        
        
}


